
class PhyScene extends BaseScene {
    protected _world: Box2D.Dynamics.b2World = null
    public get World(): Box2D.Dynamics.b2World {
        return this._world
    }
    protected _debug: Box2D.Dynamics.b2DebugDraw = null
    protected _step: number = 30
    protected _p2m: number = 10
    protected _needDebug: boolean = true

    constructor() {
        super()
    }

    protected initPhy(bg: egret.DisplayObjectContainer): void {
        let gravity: Box2D.Common.Math.b2Vec2 = new Box2D.Common.Math.b2Vec2(0, 4 * this._step / this._p2m);
        this._world = new Box2D.Dynamics.b2World(gravity, true)

        if (this._needDebug) {
            this._debug = new Box2D.Dynamics.b2DebugDraw();
            var s: egret.Sprite = new egret.Sprite();
            this._debug.SetSprite(s);
            bg.addChild(s)
            this._debug.SetDrawScale(this._p2m);
            this._debug.SetLineThickness(1);
            this._debug.SetAlpha(0.8);
            this._debug.SetFillAlpha(0.5);
            this._debug.SetFlags(Box2D.Dynamics.b2DebugDraw.e_shapeBit | Box2D.Dynamics.b2DebugDraw.e_jointBit);
            this._world.SetDebugDraw(this._debug);
        }
    }

    protected phyLoop() {
        this._world.Step(1 / this._step, 3, 6);
        if (this._debug != null) {
            this._world.DrawDebugData();
        }
    }

    public PhyLen(len: number):number{
        return len / this._p2m
    }
    public EgretLen(len: number):number{
        return len * this._p2m
    }
}